#include "maingame.h"
#include "ui_maingame.h"
#include<QPainter>
#include"mypushbutton.h"
#include<QDebug>
#include<QTimer>

Maingame::Maingame(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::Maingame)
{
    ui->setupUi(this);
    //配置主场景

    //设置固定大小
    setFixedSize(320,500);

    //设置图标
    setWindowIcon(QIcon(":/rsh/金币.jpg"));

    //设置标题
    setWindowTitle("翻金币");

    //退出按钮实现
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    //开始按钮
    MyPushButton *startBtn=new MyPushButton(":/rsh/开始游戏.jpg");
    startBtn->setParent(this);
    startBtn->move(this->width()*0.5-startBtn->width()*0.5,this->height()*0.7);

    //实例化选择关卡场景
    chooseScene=new ChooseLevelScene;

    //监听选择关卡的返回按钮的信号（放到外面，建立一次连接）
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=](){
        chooseScene->hide();//将选择关卡场景隐藏掉
        this->show();//重新显示主场景
    });

    connect(startBtn,&MyPushButton::clicked,[=](){
        //qDebug()<<"开始";
        //做一个弹起特效
        startBtn->zoom1();
        startBtn->zoom2();


        //延时进入选择关卡
        QTimer::singleShot(500,this,[=](){
            //自身隐藏
            this->hide();
            //显示选择关卡场景
            chooseScene->show();


        });

    });
}

void Maingame::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/rsh/背景.jpg");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //画背景上图标
    pix.load(":/rsh/小图标.jpg");

    pix=pix.scaled(pix.width()*0.05,pix.height()*0.05);
    painter.drawPixmap(10,30,pix);
};
Maingame::~Maingame()
{
    delete ui;
}

